<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*,java.sql.*,java.text.*, dbAccess.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Patient Visitation</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
<style type="text/css">
<!--
.style2 {font-weight: bold}
-->
</style>
<script type="text/javascript">
function clearForm()
{
	var frm = document.forms["frmEditPatientVisit"];
	frm.txtDiagnosis.value = "";
	frm.txtPrescription.value = "";
	frm.txtDosage.value = "";
	frm.txtComments.value = "";
}
</script>
</head>

<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="150" height="125" valign="top"><img src="images/caduceus.gif" alt="" name="LogoLeft" width="150" height="125" id="LogoLeft" style="background-color: #0033FF" /></td>
    <td width="692" align="center" valign="middle"><h1 align="center">CADUCEUS HOSPITAL </h1></td>
    <td width="157" valign="top"><img src="images/hospital.jpg" alt="" name="LogoRight" width="150" height="125" id="LogoRight" style="background-color: #0033FF" /></td>
  </tr>
  <tr>
    <td height="19" colspan="2" valign="top">Welcome <%=session.getAttribute("Name")%>&nbsp;<%=new java.util.Date() %>
	<td align="right"><a href="home.jsp" title="Logout">Logout</a></td>
  </tr>
</table>
<%
String visitId = request.getParameter("vId").toString();
if (visitId.equals("0"))
{
	visitId = "None."; //set empty if we're doing an add
}
String callerId = request.getParameter("callerId");

%>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
   <td height=100% width=20% valign="top" class="style2"><p>Quicklinks</p>
    <p><a href="doc2appt.jsp">View My Appointments</a></p>
    <p><a href="createDoctor.jsp">Change my Personal Information</a></p>
    <p><a href="#www.webmd.com">WebMD</a></p>
    <%
     String url = "doctorHome.jsp"; //default
     String action = "add";
     if (!visitId.equals("None.")) //if there's a visit ID, we're doing an update
     {
      action = "update";
      Login lgn2 = new Login();
      ResultSet rs2 = lgn2.getVisitDetails("Doctor",Integer.parseInt(visitId));
      rs2.next();
      int pId = rs2.getInt("tbl_appointment.PatientId");
      
      if (callerId.equals("visitList") || callerId.equals("PatientVisitAddSave")) 
      {
    	  //either we just got here from visit list/search or the update is complete from PatientVisitAddSave
    	  url = "visitList.jsp?pId=" + pId + "&callerId=editPatientVisitforDoc";
    	  if ((request.getParameter("action") != null) && request.getParameter("action").toString().equals("add"))
    	  {
    		  url = "doctorHome.jsp";
    	  }
      } 
     }
     else
     {
    	 action = "add";
     }
   
    %>
    <p><a href="<%=url%>">Back</a></p>
    <p>&nbsp;</p></td>
   
    	<%
    	
    	Login lgn = new Login();
    	ResultSet rs;
    	int apptId = 0;
    	int patientId = 0;
    	String diagnosis = "None.";
    	String prescription = "None.";
    	String dosage = "None.";
    	String comments = "None";
    	String patientFirstName = "None.";
    	String patientLastName = "None.";
    	String patientFullName = "None.";
    
    	if (!visitId.equals("None."))
    	{
    		action = "update";
    		rs = lgn.getVisitDetails("Doctor",Integer.parseInt(visitId));
    	
    		if (rs != null)
    		{
    			while (rs.next())
    			{
    				apptId = Integer.parseInt(rs.getString("tbl_visit.AppointmentId"));
    				patientId = Integer.parseInt(rs.getString("tbl_appointment.PatientId"));
    				diagnosis = rs.getString("tbl_visit.Diagnosis");
    				prescription = rs.getString("tbl_visit.Prescription");
    				dosage = rs.getString("tbl_visit.Dosage");
    				comments = rs.getString("tbl_visit.Comments");
    				patientFirstName = rs.getString("tbl_patient.FirstName");
    				patientLastName = rs.getString("tbl_patient.LastName");
    				patientFullName = patientFirstName + " " + patientLastName;
    			}
    		}
    	}
    	else
    	{
    		//doctor must be trying to add a visitation
    		action = "add";
       	 	apptId = Integer.parseInt(request.getParameter("apptId"));
       	 	patientFullName = request.getParameter("pName"); 
    	}
    	%>
    <td width=80% rowspan="2" class="style2", valign="top"><h3 align="left"><strong>Visitation Information For <%=patientFullName %> </strong></h3>
    <form id="frmEditPatientVisit" name="frmEditPatientVisit" method="post" action="PatientVisitAddSave.jsp?callerId=editPatientVisitforDoc&action=<%=action%>">
    <table width="648">
		<tr>
			<td width="117"><strong>
			  Visitation ID:				</strong></td>
		  <td width="519"><input name="txtVisitId" type="text" id="txtVisitId" value=<%=visitId %> readonly /> 
		  For Appointment ID: <input name="txtAppointmentId" type="text" id="txtAppointmentId" value=<%=apptId %> readonly /> 
		  <input name="cmdSubmit" type="submit" id="cmdSubmit" value="Submit" />
	      <input name="cmdClear" type="button" id="cmdClear" value="Clear" onclick="clearForm()"/>
	      </td>
		</tr>
				
		<tr>
			<td height="68"><strong>
			  Diagnosis
			</strong></td>
			<td>
              <textarea name="txtDiagnosis" cols="80" rows="5" id="txtDiagnosis" ><%=diagnosis%></textarea>
            </td>
		</tr>
				
		<tr>
			<td height="73"><strong>
			  Prescription
			</strong></td>
			<td>
			  <textarea name="txtPrescription" cols="80" rows="5" id="txtPrescription" ><%=prescription%></textarea>
			</td>
		</tr>
				
		<tr>
			<td height="62"><strong>
			  Dosage
			</strong></td>
			<td>
              <textarea name="txtDosage" cols="80" rows="5" id="txtDosage"><%=dosage%></textarea>
           </td>
		</tr>
				
		<tr>
			<td height="91"><strong>
			  Comments
			</strong></td>
			<td>
              <textarea name="txtComments" cols="80" rows="5" id="txtComments"><%=comments%></textarea>
           			</td>
		</tr>
	</table>
	</form>
	</td>
 
    
  </tr>
</table>
</body>
</html>
